package com.tarena.lbs.basic.controller;

import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.basic.pojo.vo.AreaVO;
import com.tarena.lbs.basic.service.AreaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 处理区域 地市数据业务的接口类
 */
@Api(tags = "区域数据管理")
@RestController
public class AreaController {

    @Autowired
    private AreaService areaService;

    @ApiOperation(value = "查询省级地区列表")
    @GetMapping("/admin/basic/area/queryList")
    public Result<List<AreaVO>> queryProvinces(){
        List<AreaVO> provinces = areaService.queryProvinces();
        return new Result<>(provinces);
    }

    @ApiOperation(value = "查询地市列表")
    @GetMapping("/admin/basic/area/{parentId}/children")
    public Result<List<AreaVO>> queryChildren(@PathVariable("parentId") Long parentId){
        List<AreaVO> children = areaService.queryChildren(parentId);
        return new Result<>(children);
    }

    @ApiOperation(value = "查询地市树")
    @GetMapping("/admin/basic/area/tree")
    public Result<List<AreaVO>> tree(){
        List<AreaVO> tree = areaService.queryTree();
        return new Result<>(tree);
    }

}
